package com.zhq.blog.core.domain.user;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import com.zhq.blog.core.domain.BaseRepository;

public interface UserRepository extends JpaRepository<User,Long>, BaseRepository<User>,JpaSpecificationExecutor<User> {
	
	@Modifying
	@Query("update User u set u.coin = u.coin + :winning where u.id = :id")
	@Transactional
	int update_user_coin_for_winning_money(@Param("id") long id,@Param("winning") long winning_money);
	
	@Modifying
	@Query("update User u set u.coin = u.coin - :bet where u.id = :id")
	@Transactional
	int update_user_coin_for_bet_money(@Param("id") long id,@Param("bet") long bet_money);
	
	@Query("select u from User u where u.userID = ? and u.password = ? and u.deleted = 0")
	List<User> find_by_id_password(long userId,String password);
	
	@Query("select u from User u where u.email = ? and u.password = ? and u.deleted = 0")
	List<User> find_by_email_password(String email,String password);
	
	@Query("select u from User u where u.userID = ?")
	List<User> find_by_UserId(long parseLong);
}
